package com.caigou.modules.center.ui

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.viewModels
import cn.bingoogolapple.bgabanner.BGABanner
import com.alibaba.android.arouter.launcher.ARouter
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.bean.Banner
import com.caigou.comm.base.bean.UserInfoBean
import com.caigou.comm.base.bus.BusKey
import com.caigou.comm.base.bus.LiveDataBus
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseFragment
import com.caigou.comm.base.ext.Resource
import com.caigou.comm.base.ext.levelAliasImage
import com.caigou.comm.base.ext.observe
import com.caigou.comm.base.ext.showToast
import com.caigou.comm.base.utils.ImageLoader
import com.caigou.comm.base.widget.VipDialog
import com.caigou.modules.center.R
import com.caigou.modules.center.bean.CsQQBean
import com.caigou.modules.center.databinding.FragmentCenterBinding
import com.caigou.modules.center.viewmodel.CenterViewModel
import dagger.hilt.android.AndroidEntryPoint


/**
 * @author #Suyghur.
 * Created on 2021/09/15
 */
@AndroidEntryPoint
class CenterFragment : BaseFragment(), View.OnClickListener {

    private var _binding: FragmentCenterBinding? = null
    private val binding get() = _binding!!

    private val centerViewModel: CenterViewModel by viewModels()

    private val bannerAdapter = BGABanner.Adapter<ImageView, String> { banner, itemView, url, position ->
        requireActivity().let {
            ImageLoader.load(it, url, itemView)
        }
    }

    private var showBalance = true
    private var vipDialog: VipDialog? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = FragmentCenterBinding.inflate(inflater, container, false)
        return _binding?.root
    }

    override fun onBack() {
    }

    override fun initView() {
        binding.centerSwipeRefreshLayout.run {
            setColorSchemeColors(resources.getColor(R.color.caigou_theme_color))
            setOnRefreshListener {
                isRefreshing = false
                if (AppBackgroundInfo.instance.hasLogin) {
                    //刷新个人信息
                    centerViewModel.getUserInfo(AppBackgroundInfo.instance.userBean!!.userId)
                } else {
                    // 没登录
                    ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                }
            }
        }

        binding.centerLayoutHeader.headerIvBoard.setOnClickListener(this)
        binding.centerLayoutHeader.headerIvMessage.setOnClickListener(this)
        binding.centerLayoutHeader.headerIvGm.setOnClickListener(this)
        binding.centerLayoutHeader.headerIvAvatar.setOnClickListener(this)
        binding.centerLayoutHeader.headerTvAction.setOnClickListener(this)
        binding.centerLayoutHeader.headerLlPager.setOnClickListener(this)

        binding.centerLayoutHeader.headerLlFollow.setOnClickListener(this)
        binding.centerLayoutHeader.headerLlFans.setOnClickListener(this)
        binding.centerLayoutHeader.headerLlDynamic.setOnClickListener(this)
        binding.centerLayoutHeader.headerLlScore.setOnClickListener(this)
        binding.centerLayoutHeader.headerLlFlower.setOnClickListener(this)

        binding.centerLayoutTools.toolsLlActive.setOnClickListener(this)
        binding.centerLayoutTools.toolsLlInvite.setOnClickListener(this)
        binding.centerLayoutTools.toolsLlCard.setOnClickListener(this)

        binding.centerLayoutChannel.channelLlTeam.setOnClickListener(this)
        binding.centerLayoutChannel.channelLlMedal.setOnClickListener(this)
        binding.centerLayoutChannel.channelLlContact.setOnClickListener(this)
        binding.centerLayoutChannel.channelLlBlackHouse.setOnClickListener(this)

        binding.centerLayoutRank.rankLlFans.setOnClickListener(this)
        binding.centerLayoutRank.rankLlLevel.setOnClickListener(this)
        binding.centerLayoutRank.rankLlCharm.setOnClickListener(this)
        binding.centerLayoutRank.rankLlContribute.setOnClickListener(this)
        binding.centerLayoutRank.rankLlMaster.setOnClickListener(this)

        binding.centerLayoutFamous.famousLlRecord.setOnClickListener(this)
        binding.centerLayoutFamous.famousLlChallenge.setOnClickListener(this)

        binding.centerLayoutService.serviceLlWebsite.setOnClickListener(this)
        binding.centerLayoutService.serviceLlPlatform.setOnClickListener(this)
        binding.centerLayoutService.serviceLlHelp.setOnClickListener(this)
        binding.centerLayoutService.serviceLlGm.setOnClickListener(this)

        binding.centerLayoutFoot.footBtnCodeCopy.setOnClickListener(this)
        binding.centerLayoutFoot.footBtnQqCopy.setOnClickListener(this)
        binding.centerLayoutFoot.footClAbout.setOnClickListener(this)

        binding.centerLayoutBalance.bannerIvEye.setOnClickListener {
            if (showBalance) {
                showBalance = false
                binding.centerLayoutBalance.bannerIvEye.setImageResource(R.drawable.img_center_hide)
                if (AppBackgroundInfo.instance.hasLogin) {
                    binding.centerLayoutBalance.balanceTvNum.text = "******"
                }
            } else {
                showBalance = true
                binding.centerLayoutBalance.bannerIvEye.setImageResource(R.drawable.img_center_show)
                if (AppBackgroundInfo.instance.hasLogin) {
                    binding.centerLayoutBalance.balanceTvNum.text = AppBackgroundInfo.instance.userBean!!.balance.toString()
                }
            }
        }

        binding.centerLayoutBalance.balanceBtnExchange.setOnClickListener {
            showToast("暂未开放，敬请期待")
        }

        binding.centerLayoutBalance.balanceBtnRecharge.setOnClickListener {
            showToast("暂未开放，敬请期待")
        }

        initDataBus()
        if (AppBackgroundInfo.instance.hasLogin) {
            handleUserInfo()
        }
    }

    override fun lazyLoad() {
        centerViewModel.getBanners()
        centerViewModel.getCsQQ()
        if (AppBackgroundInfo.instance.hasLogin) {
            //刷新个人信息
            centerViewModel.getUserInfo(AppBackgroundInfo.instance.userBean!!.userId)
        }
    }

    override fun observeViewModel() {
        super.observeViewModel()
        observe(centerViewModel.bannerLiveData, ::handleBanners)
        observe(centerViewModel.userInfoLiveData, ::handleUserInfo)
        observe(centerViewModel.buyVipLiveData, ::handleBuyVip)
        observe(centerViewModel.csQQLiveData, ::handleGetCsQQ)
    }

    private fun initDataBus() {
        observeLauncher()
        observeLogout()
        observeRefreshUserInfo()
    }

    private fun handleBanners(result: Resource<MutableList<Banner>>) {
        when (result) {
            is Resource.Loading -> {
            }
            is Resource.DataError -> {
            }
            else -> {
                result.data?.apply {
                    val bannerFeedList = ArrayList<String>()

                    forEach { banner ->
                        bannerFeedList.add(banner.bannerImg)
                    }
                    binding.banner.setDelegate { banner, itemView, feedImageUrl, position ->
                        when (this[position].id) {
                            5 -> {
                                LiveDataBus.get().with(BusKey.SWITCH_MAIN_PAGE_TAB).value = 1
                            }
                            6 -> {
                                if (AppBackgroundInfo.instance.hasLogin) {
                                    ARouter.getInstance().build(RouterPath.Tools.PAGE_TOOLS)
                                        .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_ACTIVE)
                                        .navigation()
                                }
                            }
                            7 -> {
                                if (AppBackgroundInfo.instance.hasLogin) {
                                    ARouter.getInstance().build(RouterPath.Tools.PAGE_TOOLS)
                                        .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_INVITE)
                                        .navigation()
                                }
                            }
                        }
                    }
                    binding.banner.run {
                        setAutoPlayAble(bannerFeedList.size > 1)
                        setData(bannerFeedList, null)
                        setAdapter(bannerAdapter)
                    }

                }
            }
        }
    }

    private fun handleUserInfo(result: Resource<UserInfoBean>) {
        when (result) {
            is Resource.Loading -> {
                mDialog.show()
            }
            is Resource.DataError -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (!TextUtils.isEmpty(result.errorMsg)) {
                    showToast(result.errorMsg)
                } else {
                    showToast("获取好友信息异常")
                }
            }
            is Resource.Success -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (result.data == null) {
                    return
                }
                AppBackgroundInfo.instance.userBean!!.userId = result.data!!.userId
                AppBackgroundInfo.instance.userBean!!.nickName = result.data!!.nickName
                AppBackgroundInfo.instance.userBean!!.headImg = result.data!!.headImg
                AppBackgroundInfo.instance.userBean!!.signature = result.data!!.signature
                AppBackgroundInfo.instance.userBean!!.followCount = result.data!!.followCount
                AppBackgroundInfo.instance.userBean!!.fansCount = result.data!!.fansCount
                AppBackgroundInfo.instance.userBean!!.score = result.data!!.score
                AppBackgroundInfo.instance.userBean!!.flower = result.data!!.flower
                AppBackgroundInfo.instance.userBean!!.balance = result.data!!.balance
                AppBackgroundInfo.instance.userBean!!.vip = result.data!!.vip
                handleUserInfo()
                LiveDataBus.get().with(BusKey.REFRESH_USER_INFO_FINISH, Any::class.java).value = Any()
            }
        }
    }

    private fun handleBuyVip(result: Resource<String>) {
        when (result) {
            is Resource.Loading -> {
                mDialog.show()
            }
            is Resource.DataError -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (!TextUtils.isEmpty(result.errorMsg)) {
                    showToast(result.errorMsg)
                } else {
                    showToast("获取好友信息异常")
                }
            }
            is Resource.Success -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (result.data == null) {
                    return
                }
                showToast(result.data!!)
                centerViewModel.getUserInfo(AppBackgroundInfo.instance.userBean!!.userId)
            }
        }
    }

    private fun handleGetCsQQ(result: Resource<CsQQBean>) {
        when (result) {
            is Resource.Loading -> {
                mDialog.show()
            }
            is Resource.DataError -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (!TextUtils.isEmpty(result.errorMsg)) {
                    showToast(result.errorMsg)
                } else {
                    showToast("获取客服QQ异常")
                }
            }
            is Resource.Success -> {
                mDialog.dismiss()
                binding.centerSwipeRefreshLayout.isRefreshing = false
                if (result.data == null) {
                    return
                }
                binding.centerLayoutFoot.footTvQq.text = result.data!!.qq
//                centerViewModel.getUserInfo(AppBackgroundInfo.instance.userBean!!.userId)
            }
        }
    }

    private fun observeLauncher() {
        LiveDataBus.get().with(BusKey.LOGIN_SUCCESS, Any::class.java).observe(this) {
            handleUserInfo()
        }
    }


    private fun observeLogout() {
        LiveDataBus.get().with(BusKey.LOGOUT_SUCCESS, Any::class.java).observe(this) {
            binding.centerLayoutHeader.headerClFeature.visibility = View.GONE
            binding.centerLayoutHeader.headerIvAvatar.setImageResource(R.drawable.img_comm_avatar)
            binding.centerLayoutHeader.headerTvAction.visibility = View.VISIBLE
            binding.centerLayoutHeader.headerTvName.visibility = View.GONE
            binding.centerLayoutHeader.headerTvName.text = ""

            binding.centerLayoutHeader.headerTvSignature.visibility = View.GONE
            binding.centerLayoutHeader.headerTvSignature.text = ""

            binding.centerLayoutHeader.headerIvLevel.visibility = View.GONE

            binding.centerLayoutHeader.headerLlPager.visibility = View.GONE

            binding.centerIvBanner.visibility = View.VISIBLE
            binding.centerCvBalance.visibility = View.GONE
            binding.centerLayoutVip.vipLlContainer.visibility = View.GONE

            binding.centerLayoutHeader.headerIvBoard.visibility = View.GONE
            binding.centerLayoutHeader.headerIvMessage.visibility = View.GONE
            binding.centerLayoutHeader.headerIvGm.visibility = View.GONE

            binding.centerLayoutHeader.headerTvFollowNum.text = "0"
            binding.centerLayoutHeader.headerTvFansNum.text = "0"
            binding.centerLayoutHeader.headerTvScoreNum.text = "0"
            binding.centerLayoutHeader.headerTvFlowerNum.text = "0"

        }
    }

    private fun observeRefreshUserInfo() {
        LiveDataBus.get().with(BusKey.REFRESH_USER_INFO, Any::class.java).observe(this) {
            centerViewModel.getUserInfo(AppBackgroundInfo.instance.userBean!!.userId)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        _binding = null
    }

    private fun handleUserInfo() {
        binding.centerLayoutHeader.headerTvAction.visibility = View.GONE

        binding.centerLayoutHeader.headerIvBoard.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerIvMessage.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerIvGm.visibility = View.VISIBLE

        binding.centerLayoutHeader.headerClFeature.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerTvName.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerTvName.text = AppBackgroundInfo.instance.userBean!!.nickName

        if (TextUtils.isEmpty(AppBackgroundInfo.instance.userBean!!.headImg)) {
            binding.centerLayoutHeader.headerIvAvatar.setImageResource(R.drawable.img_comm_avatar)
        } else {
            ImageLoader.loadCircle(requireActivity(), AppBackgroundInfo.instance.userBean!!.headImg, binding.centerLayoutHeader.headerIvAvatar)
        }

        binding.centerLayoutHeader.headerTvSignature.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerTvSignature.text = if (TextUtils.isEmpty(AppBackgroundInfo.instance.userBean!!.signature)) {
            "这个人很懒，他什么也没说..."
        } else {
            AppBackgroundInfo.instance.userBean!!.signature
        }

        binding.centerLayoutHeader.headerIvLevel.visibility = View.VISIBLE
        binding.centerLayoutHeader.headerIvLevel.setImageResource(levelAliasImage(AppBackgroundInfo.instance.userBean!!.level))

        binding.centerLayoutHeader.headerLlPager.visibility = View.VISIBLE

        binding.centerLayoutHeader.headerTvFollowNum.text = AppBackgroundInfo.instance.userBean!!.followCount.toString()
        binding.centerLayoutHeader.headerTvFansNum.text = AppBackgroundInfo.instance.userBean!!.fansCount.toString()
        binding.centerLayoutHeader.headerTvScoreNum.text = AppBackgroundInfo.instance.userBean!!.score.toString()
        binding.centerLayoutHeader.headerTvFlowerNum.text = AppBackgroundInfo.instance.userBean!!.flower.toString()

        binding.centerLayoutBalance.balanceTvNum.text = AppBackgroundInfo.instance.userBean!!.balance.toString()
        binding.centerLayoutFoot.footTvCode.text = "点击复制邀请码：${AppBackgroundInfo.instance.userBean!!.ownInvitationCode}"
        binding.centerLayoutFoot.footBtnCodeCopy.visibility = View.VISIBLE
        binding.centerIvBanner.visibility = View.GONE
        binding.centerCvBalance.visibility = View.VISIBLE
        if (AppBackgroundInfo.instance.userBean!!.vip == 0) {
            binding.centerLayoutVip.apply {
                vipLlContainer.visibility = View.VISIBLE
                vipBtnVip.setOnClickListener {
                    vipDialog?.apply {
                        if (isShowing) {
                            dismiss()
                        }
                        vipDialog = null
                    }
                    vipDialog = VipDialog(requireActivity())
                    vipDialog?.apply {
                        btnMonth.setOnClickListener {
                            centerViewModel.buyVip(10, AppBackgroundInfo.instance.userBean!!.userId)
                            dismiss()
                        }
                        btnYear.setOnClickListener {
                            centerViewModel.buyVip(100, AppBackgroundInfo.instance.userBean!!.userId)
                            dismiss()
                        }
                        show()
                    }
                }
            }

        } else {
            binding.centerLayoutVip.vipLlContainer.visibility = View.GONE
        }
    }

    override fun onClick(v: View?) {
        v?.apply {
            when (id) {
                binding.centerLayoutHeader.headerTvAction.id -> {
                    ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                }

                binding.centerLayoutHeader.headerIvBoard.id -> {
                    ARouter.getInstance().build(RouterPath.Personal.PAGE_PERSONAL_BOARD)
                        .withString(AppConstants.USER_ID, AppBackgroundInfo.instance.userBean!!.userId)
                        .navigation()
                }

                binding.centerLayoutHeader.headerIvMessage.id -> {
                    ARouter.getInstance().build(RouterPath.Center.PAGE_MESSAGE)
                        .navigation()
                }

                binding.centerLayoutHeader.headerIvGm.id -> {
                    ARouter.getInstance().build(RouterPath.Center.PAGE_GM)
                        .navigation()
                }

                binding.centerLayoutHeader.headerIvAvatar.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Personal.PAGE_PERSONAL_INFO)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Personal.TAG_INFO)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlPager.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Personal.PAGE_PERSONAL_PAGE)
                            .withString(AppConstants.USER_ID, AppBackgroundInfo.instance.userBean!!.userId)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlFollow.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_DETAIL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_MY_FOLLOW)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlFans.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_DETAIL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_MY_FANS)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlDynamic.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_DETAIL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_MY_DYNAMIC)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlScore.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_DETAIL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_SCORE)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutHeader.headerLlFlower.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_DETAIL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_FLOWER)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                // 必备工具
                binding.centerLayoutTools.toolsLlActive.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Tools.PAGE_TOOLS)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_ACTIVE)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutTools.toolsLlInvite.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Tools.PAGE_TOOLS)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_INVITE)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutTools.toolsLlCard.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Tools.PAGE_TOOLS)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_CARD)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                // 我的频道
                binding.centerLayoutChannel.channelLlTeam.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Channel.PAGE_CHANNEL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Channel.TAG_TEAM)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutChannel.channelLlMedal.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Channel.PAGE_CHANNEL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Channel.TAG_MEDAL)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutChannel.channelLlContact.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Channel.PAGE_CHANNEL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Channel.TAG_CONTACT)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutChannel.channelLlBlackHouse.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Channel.PAGE_CHANNEL)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Channel.TAG_BLACK_HOUSE)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlFans.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_FANS_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlFans.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_FANS_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlLevel.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_LEVEL_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlCharm.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_CHARM_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlContribute.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_CONTRIBUTION_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutRank.rankLlMaster.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Rank.PAGE_RANK)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Rank.TAG_MASTER_RANK)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                // 名人堂
                binding.centerLayoutFamous.famousLlRecord.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Famous.PAGE_MY_RECORD).navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutFamous.famousLlChallenge.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Famous.PAGE_CHALLENGE)
                            .withInt(AppConstants.FAMOUS_TYPE, 1)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                // 我的服务
                binding.centerLayoutService.serviceLlWebsite.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Service.PAGE_SERVICE)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Service.TAG_WEBSITE_COLLECT)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutService.serviceLlPlatform.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Service.PAGE_SERVICE)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Service.TAG_PLATFORM)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutService.serviceLlHelp.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Service.PAGE_SERVICE)
                            .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Service.TAG_HELP)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutService.serviceLlGm.id -> {
                    if (AppBackgroundInfo.instance.hasLogin) {
                        ARouter.getInstance().build(RouterPath.Center.PAGE_GM)
                            .navigation()
                    } else {
                        ARouter.getInstance().build(RouterPath.Login.PAGE_LOGIN).navigation()
                    }
                }

                binding.centerLayoutFoot.footBtnCodeCopy.id -> {
                    val cm = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
                    val mClipData = ClipData.newPlainText("ownInvitationCode", AppBackgroundInfo.instance.userBean!!.ownInvitationCode)
                    cm.setPrimaryClip(mClipData)
                    showToast("复制成功")
                }

                binding.centerLayoutFoot.footBtnQqCopy.id -> {
                    val cm = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
                    val mClipData = ClipData.newPlainText("csQQ", binding.centerLayoutFoot.footTvQq.text.toString())
                    cm.setPrimaryClip(mClipData)
                    showToast("复制成功")
                }

                binding.centerLayoutFoot.footClAbout.id -> {
                    ARouter.getInstance().build(RouterPath.Center.PAGE_ABOUT).navigation()
                }
            }
        }
    }
}